package com.imooc.api.config;

import com.imooc.interceptor.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * Created with IntelliJ IDEA.
 *
 * @auther Levi
 * @Date: 2021/03/13/22:37
 * @Description:
 */
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {

    @Bean
    public PassPortInterceptor passPortInterceptor() {
        return new PassPortInterceptor();
    }


    @Bean
    public UserTokenInterceptor userTokenInterceptor() {
        return new UserTokenInterceptor();
    }

    @Bean
    public UserActiveInterceptor userActiveInterceptor() {
        return new UserActiveInterceptor();
    }

    @Bean
    public AdminTokenInterceptor adminTokenInterceptor() {
        return new AdminTokenInterceptor();
    }

    @Bean
    public AdminCookieTokenInterceptor adminCookieTokenInterceptor() {
        return new AdminCookieTokenInterceptor();
    }



    @Bean
    public ArticleReadInterceptor articleReadInterceptor() {
        return new ArticleReadInterceptor();
    }


    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(passPortInterceptor())
                .addPathPatterns("/passport/getSMSCode");

        registry.addInterceptor(userTokenInterceptor())
                .addPathPatterns("/user/getAccountInfo")
                .addPathPatterns("/user/updateUserInfo")
                .addPathPatterns("/fs/uploadFace")
                .addPathPatterns("fans/follow")
                .addPathPatterns("fans/unfollow");
        //TODO，以后需要完善
//        registry.addInterceptor(userActiveInterceptor())
//                .addPathPatterns("/user/getSMSCode");

        registry.addInterceptor(adminTokenInterceptor())
                .addPathPatterns("/adminMng/addNewAdmin")
                .addPathPatterns("/adminMng/adminIsExist")
                .addPathPatterns("/adminMng/getAdminList")
                .addPathPatterns("/fs/uploadToGridFS")
                .addPathPatterns("/fs/readInGridFS")
                .addPathPatterns("/friendLinkMng/saveOrUpdateFriendLink")
                .addPathPatterns("/friendLinkMng/getFriendLinkList")
                .addPathPatterns("/friendLinkMng/delete");
        registry.addInterceptor(articleReadInterceptor())
                .addPathPatterns("/portal/article/readArticle");


      /*  registry.addInterceptor(adminCookieTokenInterceptor())
                .addPathPatterns("//fs/readInGridFS");*/
    }
}
